home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / System / Common / h / c_header < prev    next >
Text File  |  1997-03-11  |  9KB  |  318 lines

  1. /*
  2. * Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT 
  3. * NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject
  4. * to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in   
  5. * the file "Doc/License" of the Sather distribution.  The license is also  
  6. * available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.
  7. * -----> Please email comments to "sather-bugs@icsi.berkeley.edu". <-----
  8. */
  9.  
  10. /* This file is included at the head of the compiler-generated header file. */
  11.  
  12. #include <stdio.h>
  13. #include <math.h>
  14. #include <string.h>
  15. #if !defined(WIN32) && !defined (__riscos__)
  16. # include <sys/utsname.h> /* needed for detecting RISC/os 5.01 */
  17. #endif
  18. #if defined(V_RISCOS) && defined(R_5_0) /* yoshida@agusa.nuie.nagoya-u.ac.jp */
  19. # ifndef _SETJMP_H
  20. #  define _SETJMP_H
  21. #  include <setjmp.h>
  22. # endif
  23. #else
  24. # include <setjmp.h>
  25. #endif
  26. #include <setjmp.h>
  27. #include <signal.h>
  28. #include <limits.h>
  29. #include <sys/types.h>
  30. #include <stdlib.h>
  31. #include <time.h>
  32. #include <float.h>
  33.  
  34. #if !defined(__NeXT__) && !defined(WIN32)
  35. # include <unistd.h>
  36. #endif
  37.  
  38. #if !defined(__NeXT__) && !defined(__EMX__) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(WIN32) && !defined (__riscos__)
  39. #  include <values.h>
  40. #endif
  41.  
  42. #ifdef WIN32        /* From robert@crclund.abb.se */
  43. # include <io.h>
  44. # define lseek _lseek
  45. # define read _read
  46. # define open _open
  47. # define close _close
  48. # define O_RDONLY _O_RDONLY
  49. #endif
  50.  
  51. /* Determine the machine type: */
  52. # if defined(sun) && defined(sparc)
  53. #   define SPARC
  54.     /* Test for SunOS 5.x */
  55. #     include <errno.h>
  56. #     ifdef ECHRNG
  57. #       define SUNOS5
  58. #     else
  59. #       define SUNOS4
  60. #     endif
  61. # endif
  62. # if defined(NeXT) && defined(mc68000)
  63. #   define M68K
  64. #   define NEXT
  65. # endif
  66. # if defined(vax)
  67. #    define VAX
  68. #    ifdef ultrix
  69. #       define ULTRIX
  70. #    else
  71. #       define BSD
  72. #    endif
  73. # endif
  74.  
  75. #if defined(SPARC) && defined(SUNOS5) && defined(__SUNPRO_C)
  76. # include <sunmath.h>             
  77. #endif
  78.  
  79. /*
  80. ** ZALLOC(x) is a garbage collected malloc that returns zeroed memory.
  81. ** This is delegated to the collector appropriate for the target
  82. ** platform.  The _LEAF and _BIG forms denote regions that will be
  83. ** free of pointers and that will be very large.  (The latter is needed
  84. ** by the Boehm collector to do with blacklisting.)  ZINIT does any
  85. ** initialization required by memory management.
  86. */
  87.  
  88. #ifdef ZONES
  89. #  define ZALLOC(x)         zalloc(x)
  90. #  define ZALLOC_LEAF(x)     zalloc_leaf(x)
  91. #  define ZALLOC_BIG(x)     zalloc(x)
  92. #  define ZALLOC_LEAF_BIG(x)    zalloc_leaf(x)
  93. #  define ZFREE(x)        zfree(x)
  94. #  define ZINIT            zinit_globals();
  95. #else
  96. #  define ZALLOC(x)        GC_malloc(x)
  97. #  define ZALLOC_LEAF(x)    GC_malloc_atomic(x)
  98. #  define ZALLOC_BIG(x)        GC_malloc_ignore_off_page(x)
  99. #  define ZALLOC_LEAF_BIG(x)    GC_malloc_atomic_ignore_off_page(x)
  100. #  define ZFREE(x)        GC_free(x)
  101. #  define ZINIT
  102. #endif
  103.  
  104.  
  105. /*  Peter's Hack:  */
  106. /*
  107. #  define ZALLOC(x)        calloc(x, 1)
  108. #  define ZALLOC_LEAF(x)    calloc(x, 1)
  109. #  define ZALLOC_BIG(x)        calloc(x, 1)
  110. #  define ZALLOC_LEAF_BIG(x)    calloc(x, 1)
  111. #  define ZFREE(x)        free(x)
  112. #  define ZINIT
  113. */
  114.  
  115. /* OBALLOC(x) returns a zeroed memory region of size and type x.
  116.  * The compiler emits typedefs such that "x_struct" is the name
  117.  * of the struct type that *x refers to.
  118. */
  119. #define OBALLOC(x) ((x) ZALLOC(sizeof(struct x##_struct)))
  120.  
  121. /* For bootstrapping */
  122. #define OB_ALLOC(x) OBALLOC(x)
  123.  
  124. /* These may be defined as appropriate to the target system */
  125.  
  126. typedef char BOOL;
  127. #define FALSE 0
  128. #define TRUE 1
  129.  
  130. #if defined(V_RISCOS) && defined(R_5_0) /* yoshida@agusa.nuie.nagoya-u.ac.jp */
  131. # ifndef _MAXFLOAT
  132. #  define _MAXFLOAT
  133. #  define MAXFLOAT          ((float)3.40282346638528860e+38)
  134. # endif
  135. # define M_LOG2E             1.4426950408889634074
  136. #endif
  137.  
  138. #ifdef ALPHA
  139. typedef int INT;
  140. #define SUINT_MAX UINT_MAX
  141. #define SINT_MAX INT_MAX
  142. #define SINT_MIN INT_MIN
  143. #else
  144. typedef long INT;
  145. #define SUINT_MAX ULONG_MAX
  146. #define SINT_MAX LONG_MAX
  147. #define SINT_MIN LONG_MIN
  148. #endif
  149.  
  150. /* Layouts for the Sather classes which are built-in */
  151.  
  152. typedef struct {
  153.     short tag;
  154. #ifdef DESTROY_CHK
  155.     char destroyed;
  156. #endif
  157. #ifdef DETERMINISTIC
  158.     unsigned int id;
  159. #endif
  160.   } OB_HEADER;
  161.  
  162. typedef char CHAR;
  163. typedef float FLT;
  164. typedef double FLTD;
  165. typedef double FLTX;  /* This is a hack */
  166. typedef double FLTDX; /* This is a hack */
  167. typedef void* EXT_OB;
  168. #ifndef PSATHER
  169. typedef void *GATE;
  170. typedef void *MUTEX;
  171. typedef long THREAD_ID;
  172. typedef struct THREAD_ID_boxed_struct { OB_HEADER header; THREAD_ID immutable_part; } *THREAD_ID_boxed;
  173. #define THR_HASH(x) x
  174. #define thr_print_id(x,y)
  175. #define LOCK_HEADER_STRUCT
  176. #define LOCK_HEADER_STRUCT_REFS
  177. #define THREAD_ID_zero (long)0
  178. #define THREAD_ID_IS_EQ(a,b) ((a)==(b))
  179. #define THREAD_ID_IS_VOID(a)  ((a)==0)
  180. #endif
  181.  
  182.  
  183.  
  184. /* Little boxes made of ticky-tacky */
  185.  
  186. typedef struct BOOL_boxed_struct { OB_HEADER header; BOOL immutable_part; } *BOOL_boxed;
  187. typedef struct CHAR_boxed_struct { OB_HEADER header; CHAR immutable_part; } *CHAR_boxed;
  188. typedef struct INT_boxed_struct { OB_HEADER header; INT immutable_part; } *INT_boxed;
  189. typedef struct FLT_boxed_struct { OB_HEADER header; FLT immutable_part; } *FLT_boxed;
  190. typedef struct FLTD_boxed_struct { OB_HEADER header; FLTD immutable_part; } *FLTD_boxed;
  191. typedef struct FLTX_boxed_struct { OB_HEADER header; FLTX immutable_part; } *FLTX_boxed;
  192. typedef struct FLTDX_boxed_struct { OB_HEADER header; FLTDX immutable_part; } *FLTDX_boxed;
  193. typedef struct EXT_OB_boxed_struct { OB_HEADER header; EXT_OB immutable_part; } *EXT_OB_boxed;
  194.  
  195. typedef struct STR_struct {
  196.     OB_HEADER header;
  197.     INT asize;
  198.     CHAR arr_part[1];
  199. } *STR;
  200.  
  201. /* bound iter stuff: a header for an iter frame, the actual iter is yet 
  202.    not known  */
  203. typedef struct iter_frame_stub_struct {
  204.  INT state;
  205. }*iter_frame_stub;
  206.  
  207. typedef struct OB_struct {
  208.     OB_HEADER header;
  209. } *OB;
  210.  
  211. #define INT_zero (INT)0
  212. #define BOOL_zero (BOOL)0
  213. #define CHAR_zero (CHAR)0
  214. #define FLTD_zero (FLTD)0
  215. #define FLT_zero (FLT)0
  216. #define FLTX_zero (FLTX)0
  217. #define FLTDX_zero (FLTDX)0
  218. #define EXT_OB_zero (EXT_OB)0
  219.  
  220. #define STD_IS_EQ(a,b) ((a)==(b))
  221. #define INT_IS_EQ(a,b) STD_IS_EQ(a,b)
  222. #define BOOL_IS_EQ(a,b) STD_IS_EQ(a,b)
  223. #define CHAR_IS_EQ(a,b) STD_IS_EQ(a,b)
  224. #define FLTD_IS_EQ(a,b) STD_IS_EQ(a,b)
  225. #define FLT_IS_EQ(a,b) STD_IS_EQ(a,b)
  226. #define FLTX_IS_EQ(a,b) STD_IS_EQ(a,b)
  227. #define FLTDX_IS_EQ(a,b) STD_IS_EQ(a,b)
  228. #define EXT_OB_IS_EQ(a,b) STD_IS_EQ(a,b)
  229.  
  230. #define INT_IS_VOID(a) ((a)==0)
  231. #define BOOL_IS_VOID(a) ((a)==0)
  232. #define CHAR_IS_VOID(a) ((a)==0)
  233. #define FLTD_IS_VOID(a) ((a)==0.0)
  234. #define FLT_IS_VOID(a) ((a)==0.0)
  235. #define FLTX_IS_VOID(a) ((a)==0.0)
  236. #define FLTDX_IS_VOID(a) ((a)==0.0)
  237. #define EXT_OB_IS_VOID(a) ((a)==0)
  238.  
  239. #undef ferror
  240. #undef feof
  241.  
  242. /* include floating-point support */
  243. #include "floatmath.h"
  244.  
  245. /* include exception handling support */
  246. /* pSather has its own exception handling */
  247. #ifndef PSATHER
  248. #include "exception.h"
  249. #endif
  250.  
  251. STR gen_SYS_str_for_tp(INT);
  252. BOOL gen_SYS_ob_eq(OB,OB);
  253.  
  254. #define IS_ITER 0
  255.  
  256. /* include stuff for interfacing other languages */
  257. #include "fortran.h"
  258. #include "c.h"
  259.  
  260. /* 
  261.  * The definition of multiple tables (mostly generated by the compiler)
  262.  * Those tables are used for
  263.  * - GC
  264.  * - Debugging
  265.  * - to move data between clusters (pSather)
  266.  */
  267.  
  268. /* source files, used for nice error messages and debugging */
  269. extern char *source_files[];
  270. extern int sather_type_offset;
  271. struct sather_attribute {
  272.     char *sather_name;
  273.     char *c_name;
  274.     int type;
  275.     long offset;
  276.     long source;
  277. };
  278.  
  279. extern struct sather_type_description {
  280.     int *refs; /* list of offsets for reference objects, terminated with -1 */
  281.            /* void if object has no references at all. This information */
  282.            /* is obviously redundant, but speeds up pSather and GC    */
  283.            /* References in embedded value type objects have to be      */
  284.            /* mentioned too!                        */
  285.     char *sather_name;
  286.     char *c_name;
  287.     long source; /* source file and line where it is defined */
  288.     int size;
  289.     int boxed;  /* only immutable types: offset of 'immutable_part' when boxed    */
  290.     int attrs; /* No of attributes                        */
  291.     unsigned is_immutable:1;
  292.     unsigned is_ref:1;
  293.     unsigned is_abstract:1;
  294.     unsigned is_bound:1;
  295.     unsigned is_ext:1;
  296.     unsigned is_aref:1; /* last attr describs array                */
  297.     struct sather_attribute attr[1];
  298. } **sather_types;
  299.  
  300. extern struct sather_function_definition {
  301.     void (*cfunc)();              /* pointer to C function     */
  302.     long source;                /* sather file            */
  303.     char *sather_name;
  304.     char *c_name;
  305.     int args;                 /* number of args, including self */
  306.     int locals;                 /* number of locals */
  307.     struct sather_attribute attr[1];     /* first args, then locals */
  308. } *sather_functions[];
  309.     
  310. struct _func_frame {
  311.     long func;
  312.     struct _func_frame *prev;
  313.     void **args;  /* args[0]=self, first args, then locals */
  314. };
  315.  
  316. extern char *sather_prog_name;
  317.  
  318.